﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIBlend.WPF.Controls;
using System.Globalization;
using System.ComponentModel;

namespace AnonsaiWPF.CSharp
{
    /// <summary>
    /// Interaction logic for DateTimeEditor.xaml
    /// </summary>
    public partial class DateTimePickerDemo : Window, IWindow
    {
        private ErrorProvider provider = new ErrorProvider();

        public void SetTheme()
        {
        }
  
        public void ClearProvider()
        {
            this.provider.Clear();
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        public DateTimePickerDemo()
        {
            InitializeComponent();
   
            this.LayoutRoot.Children.Add(provider);

            DateTime maxValue = new DateTime(2100, 1, 1);
            DateTime minValue = new DateTime(1900, 1, 1);

            this.CultureInfoBox.Items.Add("en-US");
            this.CultureInfoBox.Items.Add("en-GB");
            this.CultureInfoBox.Items.Add("he-IL");
            this.CultureInfoBox.Items.Add("fr-FR");
            this.CultureInfoBox.Items.Add("de-DE");
            this.CultureInfoBox.SelectionChanged += new SelectionChangedEventHandler(CultureInfoBox_SelectionChanged);
      
            this.MinHeight = 500;
            this.MinWidth = 735;
        }

        void CultureInfoBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CultureInfo info = new CultureInfo(this.CultureInfoBox.SelectedItem.ToString());

            VIBlend.WPF.Controls.DateTimeEditor editor = new VIBlend.WPF.Controls.DateTimeEditor();
            editor.Culture = new CultureInfo("de-DE");

            this.FullDateTimePattern.Culture = info;
            this.ShortTime.Culture = info;
            this.LongTime.Culture = info;
            this.LongDate.Culture = info;
            this.ShortDate.Culture = info;
            this.CustomFormat.Culture = info;
        }

        void Editor_ValueChanged(object sender, EventArgs e)
        {
            VIBlend.WPF.Controls.DateTimeEditor editor = sender as VIBlend.WPF.Controls.DateTimeEditor;
            if (editor == null)
                return;

            if (editor.Value < editor.Minimum)
            {
                this.provider.SetError(editor, "Value is less than the Minimum value");
            }
            else if (editor.Value > editor.Maximum)
            {
                this.provider.SetError(editor, "Value is greater than the Maximum value!");
            }
            else this.provider.SetError(editor, "");
        }
    }
}
